import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:logger/logger.dart';
import 'package:lovify/core/constants/config.dart';
import 'package:lovify/core/utils/image.dart';
import 'package:lovify/models/user.dart';
import 'package:lovify/routes/app.dart';
import 'package:lovify/state/relation_ship_controller.dart';
import 'package:lovify/widgets/aq_button.dart';
import 'package:lovify/widgets/aq_code.dart';
import 'package:lovify/widgets/aq_scroll_body.dart';
import 'package:lovify/widgets/aq_text.dart';

class SingleHome extends StatefulWidget {
  final User user;

  const SingleHome({super.key, required this.user});

  @override
  State<SingleHome> createState() => _SingleHomeState();
}

class _SingleHomeState extends State<SingleHome> {
  final Logger _logger = Logger(printer: PrettyPrinter());
  final _rsState = Get.find<RelationshipController>();

  Future<void> _doAction() async {
    var code = await _rsState.decodeQRCode();
    _logger.i(code);
  }

  @override
  Widget build(BuildContext context) {
    return AQScrollBody(children: [
      AQCode(
        width: 200,
        height: 200,
        deviceId: widget.user.deviceId as String,
      ),
      const SizedBox(height: 12),
      const AQText(
        content: "请扫码以查看内容",
        fontSize: 24,
      ),
      const SizedBox(height: 24),
      AQButton(
        label: "开始扫码",
        onPressed: () {
          _doAction();
        },
      ),
    ]);
  }
}
